<?php

namespace App\Handlers;

use App\Models\Config\Channels;
use App\Repositories\Config\ChannelsRepository;
use Auth;

class role
{
    public static function getGamesAuth()
    {
        $admin = Auth::guard('admin')->user();
        $gamesAuth = [];
        foreach ($admin->roles as $key => $role) {
            $temp = explode(',', $role->game_id);
            if ($temp[0] != '') {
                $gamesAuth = array_merge($gamesAuth, $temp);
            }
        }
        $gamesAuth = array_unique($gamesAuth);//有权限的游戏

        return $gamesAuth;
    }

    public static function getChannelsAuth()
    {
        $admin = Auth::guard('admin')->user();
        $channelsAuth = [];
        foreach ($admin->roles as $key => $role) {
            $temp = explode(',', $role->channel_id);
            if ($temp[0] != '') {
                $channelsAuth = array_merge($channelsAuth, $temp);
            }
        }
        $channelsAuth = array_unique($channelsAuth);//有权限的游戏渠道

        return $channelsAuth;
    }

    public static function getChannelsIdAuth()
    {
        $game_id = session('game_id');
        $admin = Auth::guard('admin')->user();
        $channelsAuth = [];
        foreach ($admin->roles as $key => $role) {
            $temp = explode(',', $role->channel_id);
            if ($temp[0] != '') {
                $channelsAuth = array_merge($channelsAuth, $temp);
            }
        }
        $channelsAuth = array_unique($channelsAuth);//有权限的游戏渠道

        $channels = Channels::query()->where(['game_id' => $game_id])->whereIn('id', $channelsAuth)->get()->toArray();
        $channels = array_column($channels, 'channel_id');

        return $channels;
    }
}